{{#d-modal-body
  title=(concat "discourse_post_event.builder_modal." modalTitle)
  class="discourse-post-event-builder"
}}
  {{#conditional-loading-section isLoading=model.eventModel.isSaving}}
    <form>
      {{date-time-input-range
        from=startsAt
        to=endsAt
        toTimeFirst=true
        clearable=true
        onChange=(action "onChangeDates")
      }}

      {{#event-field class="name" label="discourse_post_event.builder_modal.name.label"}}
        {{input
          value=(readonly model.eventModel.name)
          placeholderKey="discourse_post_event.builder_modal.name.placeholder"
          input=(action (mut model.eventModel.name) value="target.value")
        }}
      {{/event-field}}

      {{#event-field class="url" label="discourse_post_event.builder_modal.url.label"}}
        {{input
          value=(readonly model.eventModel.url)
          placeholderKey="discourse_post_event.builder_modal.url.placeholder"
          input=(action (mut model.eventModel.url) value="target.value")
        }}
      {{/event-field}}

      {{#event-field label="discourse_post_event.builder_modal.status.label"}}
        <label class="radio-label">
          {{radio-button
            name="status"
            value="public"
            selection=model.eventModel.status
            onChange=(action "onChangeStatus")
          }}
          <span class="message">
            <span class="title">{{i18n "discourse_post_event.models.event.status.public.title"}}</span>
            <span class="description">{{i18n "discourse_post_event.models.event.status.public.description"}}</span>
          </span>
        </label>
        <label class="radio-label">
          {{radio-button
            name="status"
            value="private"
            selection=model.eventModel.status
            onChange=(action "onChangeStatus")
          }}
          <span class="message">
            <span class="title">{{i18n "discourse_post_event.models.event.status.private.title"}}</span>
            <span class="description">{{i18n "discourse_post_event.models.event.status.private.description"}}</span>
          </span>
        </label>
        <label class="radio-label">
          {{radio-button
            name="status"
            value="standalone"
            selection=model.eventModel.status
            onChange=(action "onChangeStatus")
          }}
          <span class="message">
            <span class="title">{{i18n "discourse_post_event.models.event.status.standalone.title"}}</span>
            <span class="description">{{i18n "discourse_post_event.models.event.status.standalone.description"}}</span>
          </span>
        </label>
      {{/event-field}}

      {{#event-field enabled=allowsInvitees label="discourse_post_event.builder_modal.invitees.label"}}
        {{group-selector
          fullWidthWrap=true
          groupFinder=groupFinder
          groupNames=model.eventModel.raw_invitees
          onChangeCallback=(action "setRawInvitees")
          placeholderKey="topic.invite_private.group_name"
        }}
      {{/event-field}}

      {{#event-field class="reminders" label="discourse_post_event.builder_modal.reminders.label"}}
        <div class="reminders-list">
          {{#each model.eventModel.reminders as |reminder|}}
            <div class="reminder-item">
              {{input
                class="reminder-value"
                min=0
                value=(readonly reminder.value)
                placeholderKey="discourse_post_event.builder_modal.name.placeholder"
                input=(action (mut reminder.value) value="target.value")
              }}

              {{combo-box
                class="reminder-unit"
                value=reminder.unit
                nameProperty=null
                valueProperty=null
                content=reminderUnits
                onChange=(action (mut reminder.unit))
              }}

              {{combo-box
                class="reminder-period"
                value=reminder.period
                nameProperty=null
                valueProperty=null
                content=reminderPeriods
                onChange=(action (mut reminder.period))
              }}

              {{d-button
                class="remove-reminder"
                icon="times"
                action=(action "removeReminder" reminder)
                disabled=isLoadingReminders
              }}
            </div>
          {{/each}}
        </div>

        {{d-button
          class="add-reminder"
          disabled=addReminderDisabled
          icon="plus"
          label="discourse_post_event.builder_modal.add_reminder"
          action=(action "addReminder")
        }}
      {{/event-field}}

      {{#event-field class="recurrence" label="discourse_post_event.builder_modal.recurrence.label"}}
        {{combo-box
          class="available-recurrences"
          value=(readonly model.eventModel.recurrence)
          content=availableRecurrences
          onChange=(action (mut model.eventModel.recurrence))
          options=(hash none="discourse_post_event.builder_modal.recurrence.none")
        }}
      {{/event-field}}

      {{#if allowedCustomFields.length}}
        {{#event-field label="discourse_post_event.builder_modal.custom_fields.label"}}
          <p class="event-field-description">{{i18n "discourse_post_event.builder_modal.custom_fields.description"}}</p>
          {{#each allowedCustomFields as |allowedCustomField|}}
            <span class="label custom-field-label">{{allowedCustomField}}</span>
            {{input
              class="custom-field-input"
              value=(readonly (get model.eventModel.custom_fields allowedCustomField))
              placeholderKey="discourse_post_event.builder_modal.custom_fields.placeholder"
              input=(action "onChangeCustomField" allowedCustomField)
            }}
          {{/each}}
        {{/event-field}}
      {{/if}}
    </form>
  {{/conditional-loading-section}}
{{/d-modal-body}}

<div class="modal-footer">
  {{#if model.eventModel.isNew}}
    {{d-button
      type="button"
      class="btn-primary"
      label="discourse_post_event.builder_modal.create"
      icon="calendar-day"
      action=(action "createEvent")
    }}
  {{else}}
    {{d-button
      type="button"
      class="btn-primary"
      label="discourse_post_event.builder_modal.update"
      icon="calendar-day"
      action=(action "updateEvent")
    }}

    {{d-button
      icon="trash-alt"
      class="btn-danger"
      action="destroyPostEvent"
    }}
  {{/if}}
</div>
